package com.fivestar.pmanager.core.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 
 * 转换JSON时格式化日期类型
 * 
 * @author admin
 */
public class JsonDateSerializer extends JsonSerializer<Date>
{

    @Override
    public void serialize(Date date, JsonGenerator jg, SerializerProvider ser)
            throws IOException
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedDate = formatter.format(date);
        jg.writeString(formattedDate);
    }

}
